<?php
	require_once('classes/All.php');
	
	$page = false;
	
	try {
		if(!isset($_REQUEST['slug'])) {
			$page = Page::Get($_GET['id']);
		}
		else {
			$pages = Page::GetAllPages(true);
			foreach($pages as $current_page) {
				if(Utilities::URLSafe($current_page['title']) == $_REQUEST['slug']) {
					$page = $current_page;
				}
			}
			
			if(!$page) {
				throw new PageNotFoundException();
			}
		}
	}
	catch(PageNotFoundException $ex) {
		HTML::ErrorPage('Page not found', 'The requested page was not found in the database.');
	}
	catch(DBConnectionException $ex) {
		HTML::ErrorPage('Database connection error', 'A database connection error occurred. Please try again in a few moments.');
	}
	catch(DBQueryException $ex) {
		HTML::ErrorPage('Database query error', 'A database query error occurred. Please try again in a few moments.');
	}
	
	HTML::Header($page['title']);
	
	Page::Display($page);
	
	HTML::Footer();
?>